If you are a WordPress developer or WordPress website owner? and looking for a way to display only published posts by default in the admin area then you are in the right place. Here I will explain every step to get the solution.
Currently, WordPress displays all pages/posts in the admin area’s list by default, regardless of whether they are published or not.
Let’s assume, I have a lot of drafts, but I’m usually more interested in editing the published pages/posts, so only to display them requires a another click and a full reload.
Is it possible to set WordPress to show only published posts and pages by default?
I’m not sure if there’s a better way, but tweaking with the global variable $submenu should probably be sufficient.
To display published article by default on post link, simply paste this code snippet in your functions.php. You can then visit “All” tab to see full list of published posts.
Are you want to get implementation help, or modify or extend the functionality of this script?
A Tutorialswebsite Expert can do it for you.
Display only published posts by default?
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
add_action( 'admin_menu', 'wptw_default_published_post' ); function wptw_default_published_post() { global $submenu; // POSTS foreach( $submenu['edit.php'] as $key => $value ) { if( in_array( 'edit.php', $value ) ) { $submenu['edit.php'][ $key ][2] = 'edit.php?post_status=publish&post_type=post'; } } } |
Now click on Posts -> All Posts in admin left Menu bar. You will get published posts list by default.
Display only published page by default?
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
add_action( 'admin_menu', 'wptw_default_published_page' ); function wptw_default_published_page() { global $submenu; // PAGES foreach( $submenu['edit.php'] as $key => $value ) { if( in_array( 'edit.php', $value ) ) { $submenu['edit.php'][ $key ][2] = 'edit.php?post_status=publish&post_type=page'; } } } |
Display only published post for Custom Post Type by default?
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
add_action( 'admin_menu', 'wptw_default_published_custom_post_type' ); function wptw_default_published_custom_post_type() { global $submenu; // OTHER POST TYPES $cpt = array( 'portfolio','recipe' ); // <--- custom post type foreach( $cpt as $pt ) { foreach( $submenu[ 'edit.php?post_type=' . $pt ] as $key => $value ) { if( in_array( 'edit.php?post_type=' . $pt, $value ) ) { $submenu[ 'edit.php?post_type='.$pt ][ $key ][2] = 'edit.php?post_status=publish&post_type=' . $pt; } } } } |
Also Read: Easy Way to Add Custom Fields into WooCommerce Checkout Page
Conclusion
Well, In this article you will get the complete steps to display only published posts by default in the admin area. You can extend the functionality as per your requirement. I hope you found this tutorial helpful for your project. Keep learning!.
Pradeep Maurya is the Professional Web Developer & Designer and the Founder of “Tutorials website”. He lives in Delhi and loves to be a self-dependent person. As an owner, he is trying his best to improve this platform day by day. His passion, dedication and quick decision making ability to stand apart from others. He’s an avid blogger and writes on the publications like Dzone, e27.co